package com.gti.mobilsafe.model;

import java.io.IOException;
import java.io.InputStream;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Xml;

import com.gti.mobilsafe.pojos.UpdateInfo;

public class UpdateInfoParse {

	public static UpdateInfo getUpdateInfo(InputStream is) throws XmlPullParserException, IOException{
		
		XmlPullParser parser = Xml.newPullParser();
		parser.setInput(is, "utf-8");
		UpdateInfo info=null;
		int type = parser.getEventType();
		while(type!=XmlPullParser.END_DOCUMENT){
			switch(type){
			case XmlPullParser.START_TAG:
				if("versioninfo".equals(parser.getName())){
					info = new UpdateInfo();
					
				}else if("update_Id".equals(parser.getName())){
					info.setUpdateId(parser.nextText());
				}else if("update_Description".equals(parser.getName())){
					info.setUpdateDescription(parser.nextText());
				}else if("update_path".equals(parser.getName())){
					info.setUpdatePath(parser.nextText());
				}
				break;
			}
		
			type = parser.next();
		}
		return info;
	}
}
